package org.finesys.common.log.trace.reflect.impl;

import lombok.extern.slf4j.Slf4j;
import org.finesys.common.log.trace.reflect.Reflect;
import org.finesys.common.log.trace.spi.annotation.Join;
import org.finesys.common.log.trace.util.LogstashUtil;
import org.finesys.common.sensitive.core.converter.SensitiveDataConverter;

import java.io.UnsupportedEncodingException;
import java.util.Objects;

@Join
@Slf4j
public class CollectionParameterReflect implements Reflect {

    @Override
    public Object reflect(Object obj) throws UnsupportedEncodingException {
        if (Objects.isNull(obj)) {
            return null;
        }
        //脱敏后参数
        try {
            return SensitiveDataConverter.invokeMsg(obj.toString());
        } catch (Exception e) {
            if (log.isErrorEnabled()) {
                log.error(LogstashUtil.exceptionMarker(), e.getMessage(), e);
            }
        }
        return "parameter is null!";

    }
}
